﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="/websocket/css/style.css">
    <title>登录</title>
</head>
<body>
    <div>
        <form action="#" class="login-form">
            <h1>用户登录</h1>
            <input type="text" name="username" id="username" placeholder="用户名" />
            <input type="password" name="password" id="password" placeholder="密码" />
            <p>用户名或密码错误</p>
            <input type="button" id="login-submit" value="登录" />
        </form>
    </div>
</body>
<script src="/websocket/js/jquery.min.js"></script>
<script>
    $("#login-submit").click(function(){
        var username = $("#username").val();
        var password = $("#password").val();
        if(!username){
            $("form > p").text("用户名为空");
            $("form > p").show();
        }else if(!password){
            $("form > p").text("密码为空");
            $("form > p").show();
        }else{
            var param = {"userName":username,"password":password};
            $.post("/websocket/login",param,function(result){
                if(result=="true"){
                    window.location.href="/websocket/list";
                }else{
                    $("form > p").text("用户名或密码错误");
                    $("form > p").show();
                }
            })
        }
    })
</script>
</html>